<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ShardingSphere 分布式数据库中间件 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e48aa 0%, #9d50bb 100%);
        }
        .code-block {
            background-color: #2d2d2d;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .section-divider {
            height: 1px;
            background: linear-gradient(90deg, transparent, rgba(0,0,0,0.1), transparent);
        }
        .first-letter:first-letter {
            float: left;
            font-size: 3.5em;
            line-height: 0.9;
            margin-right: 0.15em;
            font-weight: 700;
            color: #6e48aa;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <header class="hero-gradient text-white py-20 md:py-32 px-4">
        <div class="max-w-6xl mx-auto">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4 leading-tight">ShardingSphere</h1>
                    <h2 class="text-xl md:text-2xl font-medium mb-6 opacity-90">分布式数据库中间件解决方案</h2>
                    <p class="text-lg mb-8 opacity-90 leading-relaxed">通过分库分表、读写分离和分布式事务，解决大数据时代数据库扩展难题</p>
                    <div class="flex space-x-4">
                        <a href="#intro" class="bg-white text-purple-700 px-6 py-3 rounded-lg font-semibold hover:bg-gray-100 transition duration-300">开始探索</a>
                        <a href="#quickstart" class="border-2 border-white text-white px-6 py-3 rounded-lg font-semibold hover:bg-white hover:bg-opacity-10 transition duration-300">快速入门</a>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="relative w-full max-w-md">
                        <div class="absolute -top-10 -left-10 w-32 h-32 bg-purple-300 rounded-full mix-blend-multiply filter blur-xl opacity-70"></div>
                        <div class="absolute -bottom-8 -right-8 w-32 h-32 bg-yellow-300 rounded-full mix-blend-multiply filter blur-xl opacity-70"></div>
                        <div class="relative bg-white bg-opacity-10 backdrop-filter backdrop-blur-sm p-6 rounded-2xl shadow-xl">
                            <div class="text-center">
                                <i class="fas fa-database text-5xl mb-4 text-white opacity-90"></i>
                                <h3 class="text-xl font-semibold mb-2">分布式架构</h3>
                                <p class="text-sm opacity-80">分片 | 事务 | 治理 | 代理</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto py-12 px-4">
        <!-- Introduction Section -->
        <section id="intro" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-purple-600 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">1. 什么是 ShardingSphere？</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-gray-800">1.1 ShardingSphere 概述</h3>
                    <p class="text-gray-700 mb-6 leading-relaxed first-letter">ShardingSphere 是 Apache 软件基金会旗下的一个开源项目，专注于为数据库提供数据分片、读写分离、分布式事务和数据治理等功能。它包含多个组件，满足不同场景下的数据库扩展需求。</p>
                    
                    <div class="bg-purple-50 border-l-4 border-purple-500 p-4 mb-6 rounded">
                        <div class="flex items-start">
                            <div class="flex-shrink-0 text-purple-500">
                                <i class="fas fa-info-circle"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-purple-700">ShardingSphere 三大核心组件：ShardingSphere-JDBC（轻量级Java框架）、ShardingSphere-Proxy（数据库代理）、ShardingSphere-Sidecar（服务网格代理）</p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="bg-white p-6 rounded-xl shadow-md">
                        <div class="mermaid">
                            graph TD
                                A[ShardingSphere] --> B[ShardingSphere-JDBC]
                                A --> C[ShardingSphere-Proxy]
                                A --> D[ShardingSphere-Sidecar]
                                B --> E[数据分片]
                                B --> F[读写分离]
                                B --> G[分布式事务]
                                C --> H[透明化分片]
                                C --> I[多数据库协议]
                                D --> J[服务网格集成]
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-gray-800">1.2 为什么需要 ShardingSphere？</h3>
                    <p class="text-gray-700 mb-4 leading-relaxed">在大数据和高并发应用场景下，单一数据库很容易成为瓶颈。通过 ShardingSphere，我们可以实现：</p>
                    
                    <ul class="space-y-3 mb-6">
                        <li class="flex items-start">
                            <span class="flex-shrink-0 text-purple-500 mr-2 mt-1">
                                <i class="fas fa-check-circle"></i>
                            </span>
                            <span class="text-gray-700"><strong>分库分表</strong>：将数据按照一定规则分散到多个数据库中，分散压力</span>
                        </li>
                        <li class="flex items-start">
                            <span class="flex-shrink-0 text-purple-500 mr-2 mt-1">
                                <i class="fas fa-check-circle"></i>
                            </span>
                            <span class="text-gray-700"><strong>读写分离</strong>：将读写操作分开处理，读操作走从库，写操作走主库，提高性能和可用性</span>
                        </li>
                        <li class="flex items-start">
                            <span class="flex-shrink-0 text-purple-500 mr-2 mt-1">
                                <i class="fas fa-check-circle"></i>
                            </span>
                            <span class="text-gray-700"><strong>分布式事务</strong>：在分布式场景下保证数据一致性，支持 XA、TCC 等事务模式</span>
                        </li>
                        <li class="flex items-start">
                            <span class="flex-shrink-0 text-purple-500 mr-2 mt-1">
                                <i class="fas fa-check-circle"></i>
                            </span>
                            <span class="text-gray-700"><strong>数据治理</strong>：支持数据脱敏、SQL 审计和影子库压测，提升安全性与监控能力</span>
                        </li>
                    </ul>
                </div>
                
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-gray-800">1.3 与其他方案的对比</h3>
                    <p class="text-gray-700 mb-6 leading-relaxed">相较于 MyCAT、TDDL 等传统方案，ShardingSphere 提供了更为丰富的功能和更灵活的扩展性，同时支持多种部署模式（JDBC、Proxy），使得开发者可以根据实际需求选择最合适的解决方案。</p>
                    
                    <div class="overflow-x-auto">
                        <table class="min-w-full bg-white rounded-lg overflow-hidden">
                            <thead class="bg-gray-100">
                                <tr>
                                    <th class="py-3 px-4 text-left text-gray-700 font-semibold">特性</th>
                                    <th class="py-3 px-4 text-left text-gray-700 font-semibold">ShardingSphere</th>
                                    <th class="py-3 px-4 text-left text-gray-700 font-semibold">MyCAT</th>
                                </tr>
                            </thead>
                            <tbody class="divide-y divide-gray-200">
                                <tr>
                                    <td class="py-3 px-4">分库分表</td>
                                    <td class="py-3 px-4 text-green-600">✓</td>
                                    <td class="py-3 px-4 text-green-600">✓</td>
                                </tr>
                                <tr class="bg-gray-50">
                                    <td class="py-3 px-4">读写分离</td>
                                    <td class="py-3 px-4 text-green-600">✓</td>
                                    <td class="py-3 px-4 text-green-600">✓</td>
                                </tr>
                                <tr>
                                    <td class="py-3 px-4">分布式事务</td>
                                    <td class="py-3 px-4 text-green-600">✓</td>
                                    <td class="py-3 px-4 text-gray-400">✗</td>
                                </tr>
                                <tr class="bg-gray-50">
                                    <td class="py-3 px-4">数据脱敏</td>
                                    <td class="py-3 px-4 text-green-600">✓</td>
                                    <td class="py-3 px-4 text-gray-400">✗</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>
        
        <div class="section-divider my-16"></div>
        
        <!-- Core Features Section -->
        <section id="features" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-purple-600 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">2. ShardingSphere 的核心功能</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="feature-card bg-white p-6 rounded-xl shadow-md hover:shadow-lg transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-project-diagram text-purple-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">2.1 数据分片（Sharding）</h3>
                    </div>
                    <p class="text-gray-700 mb-4">数据分片是指将单个数据库中的数据，根据预设规则拆分成多个子数据块，然后分布到不同的数据库实例中。</p>
                    
                    <div class="bg-gray-50 p-4 rounded-lg">
                        <p class="text-sm font-medium text-gray-700 mb-2">常用分片策略：</p>
                        <ul class="list-disc pl-5 text-sm text-gray-600 space-y-1">
                            <li><strong>水平分片</strong>：例如，将订单数据根据用户ID进行拆分</li>
                            <li><strong>分片算法</strong>：支持哈希分片、范围分片和自定义分片算法</li>
                        </ul>
                    </div>
                </div>
                
                <div class="feature-card bg-white p-6 rounded-xl shadow-md hover:shadow-lg transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-exchange-alt text-blue-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">2.2 读写分离</h3>
                    </div>
                    <p class="text-gray-700 mb-4">读写分离是通过将数据库的写操作和读操作分开处理，实现高并发访问。ShardingSphere 提供了负载均衡策略，如轮询和权重分配。</p>
                    
                    <div class="bg-gray-50 p-4 rounded-lg">
                        <div class="mermaid">
                            graph LR
                                A[应用] -->|写操作| B[主库]
                                A -->|读操作| C[从库1]
                                A -->|读操作| D[从库2]
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="feature-card bg-white p-6 rounded-xl shadow-md hover:shadow-lg transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 bg-green-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-random text-green-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">2.3 分布式事务</h3>
                    </div>
                    <p class="text-gray-700 mb-4">在分布式场景下，多数据库之间需要保持数据一致性。ShardingSphere 支持柔性事务，包括 XA 事务、BASE 事务和 TCC（Try-Confirm-Cancel）事务方案。</p>
                    
                    <div class="flex space-x-3">
                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">XA</span>
                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">BASE</span>
                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-purple-100 text-purple-800">TCC</span>
                    </div>
                </div>
                
                <div class="feature-card bg-white p-6 rounded-xl shadow-md hover:shadow-lg transition duration-300">
                    <div class="flex items-center mb-4">
                        <div class="w-10 h-10 bg-yellow-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-shield-alt text-yellow-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">2.4 数据治理</h3>
                    </div>
                    <p class="text-gray-700 mb-4">除了分片和事务，ShardingSphere 还支持数据脱敏、SQL 审计和影子库压测等功能，帮助企业在数据安全和监控上做得更好，确保系统运行稳定可靠。</p>
                    
                    <div class="flex space-x-3">
                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800">数据脱敏</span>
                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800">SQL审计</span>
                        <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800">影子库压测</span>
                    </div>
                </div>
            </div>
        </section>
        
        <div class="section-divider my-16"></div>
        
        <!-- Quick Start Section -->
        <section id="quickstart" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-purple-600 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">3. ShardingSphere-JDBC 快速入门</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-gray-800">3.1 环境搭建</h3>
                    <p class="text-gray-700 mb-6 leading-relaxed">首先，在 Maven 项目中添加 ShardingSphere-JDBC 的依赖：</p>
                    
                    <div class="code-block p-4 mb-6">
                        <pre class="text-gray-200 text-sm overflow-x-auto"><code>&lt;dependency&gt;
    &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt;
    &lt;artifactId&gt;shardingsphere-jdbc-core-spring-boot-starter&lt;/artifactId&gt;
    &lt;version&gt;5.2.0&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
                    </div>
                    
                    <p class="text-gray-700 mb-4 leading-relaxed">确保项目中已经配置了 Spring Boot 环境。</p>
                </div>
                
                <div>
                    <h3 class="text-2xl font-semibold mb-4 text-gray-800">3.2 数据源配置</h3>
                    <p class="text-gray-700 mb-4 leading-relaxed">在 <code class="bg-gray-100 px-1 py-0.5 rounded">application.yml</code> 中配置数据源和分片规则：</p>
                    
                    <div class="code-block p-4">
                        <pre class="text-gray-200 text-sm overflow-x-auto"><code>spring:
  shardingsphere:
    datasource:
      names: ds0, ds1
      ds0:
        type: com.zaxxer.hikari.HikariDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        jdbc-url: jdbc:mysql://localhost:3306/ds0
        username: root
        password: root
      ds1:
        type: com.zaxxer.hikari.HikariDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        jdbc-url: jdbc:mysql://localhost:3306/ds1
        username: root
        password: root
    sharding:
      tables:
        t_order:
          actual-data-nodes: ds$->{0..1}.t_order_$->{0..1}
          table-strategy:
            inline:
              sharding-column: order_id
              algorithm-expression: t_order_$->{order_id % 2}
          key-generator:
            column: order_id
            type: SNOWFLAKE</code></pre>
                    </div>
                </div>
            </div>
            
            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800">3.3 编写测试代码</h3>
                <p class="text-gray-700 mb-6 leading-relaxed">在 Spring Boot 应用中，可以通过 MyBatis 或 JPA 进行数据库操作。下面是一个简单的订单插入和查询接口示例：</p>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <div class="bg-gray-800 rounded-t-lg px-4 py-2">
                            <span class="inline-block w-3 h-3 bg-red-500 rounded-full mr-2"></span>
                            <span class="inline-block w-3 h-3 bg-yellow-500 rounded-full mr-2"></span>
                            <span class="inline-block w-3 h-3 bg-green-500 rounded-full"></span>
                            <span class="text-gray-400 text-sm ml-2">OrderMapper.java</span>
                        </div>
                        <div class="code-block p-4">
                            <pre class="text-gray-200 text-sm overflow-x-auto"><code>public interface OrderMapper {
    
    @Insert("INSERT INTO t_order (order_id, user_id, status, " +
            "create_time, amount) VALUES (#{orderId}, " +
            "#{userId}, #{status}, #{createTime}, #{amount})")
    int insertOrder(Order order);

    @Select("SELECT order_id, user_id, status, " +
            "create_time, amount FROM t_order " +
            "WHERE order_id = #{orderId}")
    Order selectOrderById(Long orderId);
}</code></pre>
                        </div>
                    </div>
                    
                    <div>
                        <div class="bg-gray-800 rounded-t-lg px-4 py-2">
                            <span class="inline-block w-3 h-3 bg-red-500 rounded-full mr-2"></span>
                            <span class="inline-block w-3 h-3 bg-yellow-500 rounded-full mr-2"></span>
                            <span class="inline-block w-3 h-3 bg-green-500 rounded-full"></span>
                            <span class="text-gray-400 text-sm ml-2">OrderMapperTest.java</span>
                        </div>
                        <div class="code-block p-4">
                            <pre class="text-gray-200 text-sm overflow-x-auto"><code>@SpringBootTest
public class OrderMapperTest {

    @Autowired
    private OrderMapper orderMapper;

    @Test
    public void testInsertAndSelectOrder() {
        Order order = new Order();
        order.setOrderId(101L);
        order.setUserId(1001L);
        order.setStatus("CREATED");
        order.setCreateTime(new Date());
        order.setAmount(new BigDecimal("99.99"));

        int rows = orderMapper.insertOrder(order);
        Order queriedOrder = orderMapper.selectOrderById(101L);
        assertThat(queriedOrder).isNotNull();
    }
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-blue-50 border-l-4 border-blue-500 p-4 rounded">
                <div class="flex items-start">
                    <div class="flex-shrink-0 text-blue-500">
                        <i class="fas fa-lightbulb"></i>
                    </div>
                    <div class="ml-3">
                        <p class="text-sm text-blue-700">测试说明：通过这个测试代码，我们可以直观地验证 ShardingSphere-JDBC 的分片和路由功能是否生效。实际运行时，可以在日志中查看 SQL 执行情况，观察数据是如何在 t_order_0 和 t_order_1 之间分布的。</p>
                    </div>
                </div>
            </div>
        </section>
        
        <div class="section-divider my-16"></div>
        
        <!-- Spring Boot Integration Section -->
        <section id="springboot" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-purple-600 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800">5. ShardingSphere 与 Spring Boot 整合实战</h2>
            </div>
            
            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800">5.1 需求分析</h3>
                <p class="text-gray-700 mb-6 leading-relaxed first-letter">构建一个电商订单系统，其中订单数据按用户 ID 分库分表，查询操作支持读写分离。要求订单表包含订单 ID、用户 ID、商品信息、订单状态等字段，并根据用户 ID 进行水平分片，数据分布在多个数据库和表中。</p>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <div class="bg-white p-6 rounded-xl shadow-md">
                            <div class="mermaid">
                                graph LR
                                    A[应用] --> B[ShardingSphere-JDBC]
                                    B --> C[主库1]
                                    B --> D[主库2]
                                    C --> E[从库1-1]
                                    C --> E2[从库1-2]
                                    D --> F[从库2-1]
                                    D --> F2[从库2-2]
                            </div>
                        </div>
                    </div>
                    <div>
                        <h4 class="text-lg font-semibold mb-3 text-gray-800">系统架构特点：</h4>
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <span class="flex-shrink-0 text-purple-500 mr-2 mt-1">
                                    <i class="fas fa-check-circle"></i>
                                </span>
                                <span class="text-gray-700">订单数据按用户ID分片到不同数据库</span>
                            </li>
                            <li class="flex items-start">
                                <span class="flex-shrink-0 text-purple-500 mr-2 mt-1">
                                    <i class="fas fa-check-circle"></i>
                                </span>
                                <span class="text-gray-700">读写分离架构提升查询性能</span>
                            </li>
                            <li class="flex items-start">
                                <span class="flex-shrink-0 text-purple-500 mr-2 mt-1">
                                    <i class="fas fa-check-circle"></i>
                                </span>
                                <span class="text-gray-700">分布式事务保证数据一致性</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800">5.2 搭建 Spring Boot 项目</h3>
                <p class="text-gray-700 mb-6 leading-relaxed">创建一个 Spring Boot 项目，并在 <code class="bg-gray-100 px-1 py-0.5 rounded">pom.xml</code> 中添加 ShardingSphere-JDBC 依赖，配置 <code class="bg-gray-100 px-1 py-0.5 rounded">application.yml</code> 文件设置数据源、分片规则和读写分离规则。</p>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <div class="bg-gray-800 rounded-t-lg px-4 py-2">
                            <span class="inline-block w-3 h-3 bg-red-500 rounded-full mr-2"></span>
                            <span class="inline-block w-3 h-3 bg-yellow-500 rounded-full mr-2"></span>
                            <span class="inline-block w-3 h-3 bg-green-500 rounded-full"></span>
                            <span class="text-gray-400 text-sm ml-2">pom.xml</span>
                        </div>
                        <div class="code-block p-4">
                            <pre class="text-gray-200 text-sm overflow-x-auto"><code>&lt;dependency&gt;
    &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt;
    &lt;artifactId&gt;shardingsphere-jdbc-core-spring-boot-starter&lt;/artifactId&gt;
    &lt;version&gt;5.2.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;mysql&lt;/groupId&gt;
    &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.mybatis.spring.boot&lt;/groupId&gt;
    &lt;artifactId&gt;mybatis-spring-boot-starter&lt;/artifactId&gt;
    &lt;version&gt;2.2.0&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
                        </div>
                    </div>
                    
                    <div>
                        <div class="bg-gray-800 rounded-t-lg px-4 py-2">
                            <span class="inline-block w-3 h-3 bg-red-500 rounded-full mr-2"></span>
                            <span class="inline-block w-3 h-3 bg-yellow-500 rounded-full mr-2"></span>
                            <span class="inline-block w-3 h-3 bg-green-500 rounded-full"></span>
                            <span class="text-gray-400 text-sm ml-2">application.yml</span>
                        </div>
                        <div class="code-block p-4">
                            <pre class="text-gray-200 text-sm overflow-x-auto"><code>spring:
  shardingsphere:
    datasource:
      names: ds0, ds1, ds0_slave, ds1_slave
      ds0: # 主库配置...
      ds0_slave: # 从库配置...
      ds1: # 主库配置...
      ds1_slave: # 从库配置...
    rules:
      readwrite-splitting:
        data-sources:
          ds0:
            type: static
            write-data-source-name: ds0
            read-data-source-names:
              - ds0_slave
          ds1:
            type: static
            write-data-source-name: ds1
            read-data-source-names:
              - ds1_slave</code></pre>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800">5.4 开发订单管理模块</h3>
                <p class="text-gray-700 mb-6 leading-relaxed">使用 Spring Boot 集成 MyBatis 实现订单表的增删改查操作，编写 Service、Controller 和 Mapper 层代码。</p>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <div class="bg-gray-800 rounded-t-lg px-4 py-2">
                            <span class="inline-block w-3 h-3 bg-red-500 rounded-full mr-2"></span>
                            <span class="inline-block w-3 h-3 bg-yellow-500 rounded-full mr-2"></span>
                            <span class="inline-block w-3 h-3 bg-green-500 rounded-full"></span>
                            <span class="text-gray-400 text-sm ml-2">OrderController.java</span>
                        </div>
                        <div class="code-block p-4">
                            <pre class="text-gray-200 text-sm overflow-x-auto"><code>@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/create")
    public String createOrder(@RequestBody Order order) {
        orderService.createOrder(order);
        return "订单创建成功！";
    }

    @GetMapping("/query")
    public Order queryOrder(@RequestParam Long orderId) {
        return orderService.getOrder(orderId);
    }
}</code></pre>
                        </div>
                    </div>
                    
                    <div>
                        <div class="bg-gray-800 rounded-t-lg px-4 py-2">
                            <span class="inline-block w-3 h-3 bg-red-500 rounded-full mr-2"></span>
                            <span class="inline-block w-3 h-3 bg-yellow-500 rounded-full mr-2"></span>
                            <span class="inline-block w-3 h-3 bg-green-500 rounded-full"></span>
                            <span class="text-gray-400 text-sm ml-2">OrderService.java</span>
                        </div>
                        <div class="code-block p-4">
                            <pre class="text-gray-200 text-sm overflow-x-auto"><code>@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Transactional
    public void createOrder(Order order) {
        orderMapper.insertOrder(order);
    }

    public Order getOrder(Long orderId) {
        return orderMapper.selectOrderById(orderId);
    }
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>
    
    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-10">
        <div class="max-w-6xl mx-auto px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-xl font-semibold text-white mb-2">技术小馆</h3>
                    <p class="text-sm">探索技术的无限可能</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-purple-400 hover:text-purple-300 transition duration-200">http://www.yuque.com/jtostring</a>
                </div>
            </div>
        </div>
    </footer>
    
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>